package com.zztl.infiniteBand.presenter

import android.content.Context
import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.FirmwareVersionBean
import com.zztl.infiniteBand.model.PersonInfoBean
import com.zztl.infiniteBand.model.UserAssetsBean
import com.zztl.infiniteBand.net.FilterSubscriber
import com.zztl.infiniteBand.net.FilterSubscriber2
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.FirmwareVersionRequest
import com.zztl.infiniteBand.ui.view.mvpview.MineView


/**
 * @desc
 * @auth ${user}
 * @time 2018/6/12  16:59
 */
class MinePresenter : BasePresenter<MineView>() {
    fun getUserAssets(context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService
                        .getAssets("")).subscribe(object : FilterSubscriber<UserAssetsBean>(context) {
                    override fun success(userAssetsBean: UserAssetsBean) {
                        view!!.getAssetsSuccess(userAssetsBean)
                    }

                    override fun fail() {
                        view!!.fail()
                    }

                }))
    }

    fun getUserInfo(context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService
                        .getInfo("")).subscribe(object : FilterSubscriber2<PersonInfoBean>(context) {
                    override fun success(infoBean: PersonInfoBean) {
                        view!!.getInfoSuccess(infoBean)
                    }

                    override fun fail(msg: String?) {
                        view!!.fail()
                    }
                }))
    }

    fun getUserAssets2(context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService
                        .getAssets("")).subscribe(object : FilterSubscriber2<UserAssetsBean>(context) {
                    override fun success(userAssetsBean: UserAssetsBean) {
                        view!!.getAssetsSuccess(userAssetsBean)
                    }

                    override fun fail(msg: String?) {
                        view!!.fail()
                    }
                }))
    }

    fun getFirmwareVersion(request: FirmwareVersionRequest, context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.getFirmwareVersion(DataConverter.instance.toJson(request)))
                .subscribe(object : FilterSubscriber2<FirmwareVersionBean>(context) {
                    override fun success(bean: FirmwareVersionBean) {
                        view!!.getVersion(bean)
                    }

                    override fun fail(message: String?) {

                    }


                }))
    }
}
